package com.xjtu.project.controller.user;

import com.xjtu.project.common.utls.JsonResponse;
import com.xjtu.project.model.domain.Shoe;
import com.xjtu.project.model.vo.ShoeCategoryVO;
import com.xjtu.project.model.vo.ShoeCnVO;
import com.xjtu.project.model.vo.ShoeVO;
import com.xjtu.project.service.ShoeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/user")
public class ShoeUserController {

    @Autowired
    private ShoeService shoeService;

    @GetMapping("shoe/{id}")
    public JsonResponse getShoe(@PathVariable("id") Long id) {
        ShoeVO shoe = shoeService.getByIdMy(id);
        return JsonResponse.success(shoe);
    }

    @GetMapping("shoe/list")
    public JsonResponse getShoeList() {
        List<ShoeCategoryVO> lists = shoeService.getByCategory();
        return JsonResponse.success(lists);
    }
    @GetMapping("shoe")
    public JsonResponse getShoeList(Integer categoryId) {
        //根据分类id查商品
        List<ShoeCnVO> lists = shoeService.getByCategoryId(categoryId);
        return JsonResponse.success(lists);
    }
    //根据名字模糊匹配商品
    @GetMapping("shoe/name")
    public JsonResponse getShoeList(@RequestParam("name") String name) {
        List<ShoeCnVO> lists = shoeService.getByName(name);
        return JsonResponse.success(lists);
    }
}
